<?php
/**
 * The Template for displaying a single posts.
 *
 * @file      single.php
 * @package   pncm
 * @author    Ambient digital.
 * @link 	  http://ambientdigital.com
 */
 
?>
<?php get_header(); ?>


<?php $category = get_the_category(); ?>
<div class="content">
		<div class="wrapper">
			<div class="container">
				<div class="left-block full-width-md full-width-sm full-width-xs">
					<div class="block-row">
						<div class="detail">
                                <?php if (have_posts()) { ?>		
                        			<?php while (have_posts()) : the_post();?>
                                    
                                    <div class="detail-head">
        								<div class="breadscrum">
        									<a href="<?php echo esc_url( get_category_link( $category[0]->category_parent ) ); ?>"><h3><?php echo  ($category[0]->category_parent > 0)? get_cat_name($category[0]->category_parent).' > ' : ""; ?> </h3></a>
                                            <a href="<?php echo esc_url( get_category_link( $category[0]->term_id ) ); ?>"><span><?php  echo $category[0]->cat_name;?> </span></a> 
        								</div>
        								<span class="date-info"><?php the_date('H:i  d/m/Y'); ?></span>
        								
        							</div>
        							<div class="clear"> </div>
                                    <h1> <?php the_title()?></h1>
                                    
	                                <div class="clear"> </div>
                                    <div class="detail-content">
        								<?php the_content(); ?>	
										<a href="http://www.enang.net"></a>
        							</div>
                                    <div class="clear"> </div>
        							<div class="source-post">
        								<p><?php echo get_field('author');?></p>
                    					<p>Nguồn: <?php echo get_field('source');?></p>
                    					<p>Bài gốc: <?php echo get_field('source_url');?></p>
        							</div>
        							<div class="like-share">
        								<iframe src="https://www.facebook.com/plugins/like.php?href=<?php esc_url(the_permalink())?>;width&amp;layout=button&amp;action=like&amp;show_faces=true&amp;share=true&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px;" allowTransparency="true"></iframe>
        							</div>
                                    <div class="clear"> </div>
        							<div class="detail-tag"> <?php $posttags = get_the_tags(); //var_dump($posttags);?>
                                        <?php if(!empty($posttags)){?>
        								<ul> 
                                            <?php foreach($posttags as $tag){?>
                                                <li style="background: <?php echo get_random_color(); ?>;" > <a href="<?php echo get_tag_link($tag->term_id); ?>"> <?php echo $tag->name; ?></a> </li>
                                            <?php } ?>
        								
        								</ul>
                                        <?php } ?>
        							</div>
                                    <?php setPostViews(get_the_ID());  endwhile; ?> 
                                    
                    		
                        		<?php } else { ?>
                        		  <div class="detail-content">
                        				<h1 class="single-title" >Nothing found</h1>
                        					
                        			</div>
                        			
                        		<?php } ?> <!-- /have_posts -->	
                           
						</div>
					</div>
					<div class="clear"> </div>
					<div class="block-row">
						<h2 class="relate_tit"> Tin liên quan</h2>
						<ul class="same-cate-items">
                            <?php   $postID_exclude = array(); array_push($postID_exclude,get_the_ID());
                                    $args = array(
                                        'cat'                 => $category[0]->term_id,
                                        'post__not_in'        => $postID_exclude,
                                        'posts_per_page'      => 6,
                                        'orderby'             =>  'meta_value_num',
                                        'order'               => 'DESC',
                                    );
                                $the_query = new WP_Query($args);
                                // The Loop
                                if ( $the_query->have_posts() ) {
                                	
                                	while ( $the_query->have_posts() ) {
                                		$the_query->the_post();
                                        array_push($postID_exclude,get_the_ID()); 
                                        ?>
                                        <li>
                							<div class="news-item" style="position: absolute;"> 
                								<a href="<?php esc_url(the_permalink())?>" style="background:url(<?php echo get_bg_image(get_the_ID());?>) no-repeat; background-size: cover;" class="img"><img src="<?php echo get_bg_image(get_the_ID());?>" alt="<?php the_title() ?> "/></a>
                								<a href="<?php esc_url(the_permalink())?>"> <?php the_title() ?> </a>
                							</div>
                						</li>
                                        
	                       <?php }} wp_reset_postdata(); ?>
                        
						</ul>
					</div>
					<div class="clear"> </div>
					<div class="block-row">
						<h2 class="relate_tit"> Tin cùng chuyên mục</h2>
						<ul class="same-cate-items">
                            <?php   $args = array(
                                        'cat'                 => $category[0]->term_id,
                                        'post__not_in'        => $postID_exclude,
                                        'posts_per_page'      => 6,
                                        'orderby'             =>  'date',
                                        'order'               => 'DESC',
                                    );
                                $the_query = new WP_Query($args);
                                // The Loop
                                if ( $the_query->have_posts() ) {
                                	
                                	while ( $the_query->have_posts() ) {
                                		$the_query->the_post();
                                        ?>
                                        <li>
                							<div class="news-item" style="position: absolute;"> 
                								<a href="<?php esc_url(the_permalink())?>" style="background:url(<?php echo get_bg_image(get_the_ID());?>) no-repeat; background-size: cover;" class="img"><img src="<?php echo get_bg_image(get_the_ID());?>" alt="<?php the_title() ?> "/></a>
                								<a href="<?php esc_url(the_permalink())?>"> <?php the_title() ?> </a>
                							</div>
                						</li>
                                        
	                       <?php }} wp_reset_postdata(); ?>
                        
						</ul>
					</div>
				</div><!--End left-block-->
				<div class="right-block hidden-md hidden-sm hidden-xs" id="right-bar">
					<div class="block-row">
						<div class="items-list">
							<a href="#"><img src="<?php echo get_template_directory_uri() ?>/images/banner_300x250.png" alt="fadf"/></a>
						</div>
					</div><!--End block-row-->
					<div class="clear"> </div>
					<div class="block-row cate-right-bar">
						<h1> <span>TOP</span> ẨM THỰC</h1>
						<ul class="items-list">
                            <?php $args = array(
                                        'category_name'      => 'am-thuc',
                                        'posts_per_page'    => 6,
                                        'orderby'           => 'meta_value_num',
                                        'orderby'           => 'date', 
                                        'order'             => 'DESC'
                                   );
                                   $the_query = new WP_Query($args);
                                   // The Loop
                                   if ( $the_query->have_posts() ) {
                                        while ( $the_query->have_posts() ) {
                                            $the_query->the_post();?>
                                            <li>
                								<div class="news-item" > 
                									<a href="<?php esc_url(the_permalink())?>" style="background:url(<?php echo get_bg_image(get_the_ID());?>) no-repeat; background-size: cover;" class="img_rblock">
                										<img src="<?php echo get_bg_image(get_the_ID());?>" alt="<?php the_title() ?>"/>
                									</a>
                									<a href="<?php esc_url(the_permalink())?>"> <?php the_title() ?> </a>
                								</div>
                							</li>
                							<div class="clear"> </div>
                                            
                                                    
                            <?php  }} wp_reset_postdata(); ?>		
						</ul>
						<a href="<?php echo esc_url( home_url( '/' ) ); ?>chuyen-muc/am-thuc" class="crb-view-more">Xem thêm <span> Ẩm Thực</span></a>
					</div><!--End block-row-->
					<div class="clear"> </div>
					<div class="block-row">
						<div class="items-list">
							<img src="<?php echo get_template_directory_uri() ?>/images/banner_300x250.png" alt="fadf"/>
						</div>
					</div><!--End block-row-->
					<div class="clear"> </div>
					<div class="block-row cate-right-bar">
						<h1> <span>TOP</span> GIA ĐÌNH</h1>
						<ul class="items-list">
                            <?php $args = array(
                                        'category_name'      => 'gia-dinh',
                                        'posts_per_page'    => 6,
                                        'orderby'           => 'meta_value_num',
                                        'orderby'           => 'date', 
                                        'order'             => 'DESC'
                                   );
                                   $the_query = new WP_Query($args);
                                   // The Loop
                                   if ( $the_query->have_posts() ) {
                                        while ( $the_query->have_posts() ) {
                                            
                                            $the_query->the_post();?>
                                            <li>
                								<div class="news-item" > 
                									<a href="<?php esc_url(the_permalink())?>" style="background:url(<?php echo get_bg_image(get_the_ID());?>) no-repeat; background-size: cover;" class="img_rblock">
                										<img src="<?php echo get_bg_image(get_the_ID());?>" alt="<?php the_title() ?>"/>
                									</a>
                									<a href="<?php esc_url(the_permalink())?>"> <?php the_title() ?> </a>
                								</div>
                							</li>
                							<div class="clear"> </div>
                                            
                                                    
                            <?php  }} wp_reset_postdata(); ?>		
						</ul>
						<a href="<?php echo esc_url( home_url( '/' ) ); ?>chuyen-muc/gia-dinh" class="crb-view-more">Xem thêm <span> Gia đình</span></a>
					</div><!--End block-row-->
					<div class="clear"> </div>
					<div class="block-row" id="left-fixed-sidebar">
						<div class="items-list">
							<a href="#"><img src="<?php echo get_template_directory_uri() ?>/images/banner_300x250.png" alt="fadf"/></a>
						</div>
					</div><!--End block-row-->
					<div class="clear"> </div>
					
				</div><!--End right-block-->	
			</div><!--End container-->
		</div><!--End wrapper-->
</div><!--End content-->
<script>
    $(function(){ // document ready
 
      var stickyTop = $('#left-fixed-sidebar').offset().top + $('#left-fixed-sidebar').height();
      var limit = $('#scrolltop').offset().top ;
      var right_bar_height = $('#right-bar').offset().top + $('#right-bar').height();
      //alert(limit);
      $(window).scroll(function(){ // scroll event  
        var windowTop = $(window).scrollTop(); // returns number
        var lenth = $('#left-fixed-sidebar').height() + windowTop ;
         if (windowTop > right_bar_height) {
            if( lenth > limit ){
                $('#left-fixed-sidebar').css({ position: 'fixed', top: '0'});
            }
            else
            {
                $('#left-fixed-sidebar').css({ position: 'fixed', top: 29 });
            }
          
        }
        else {
          $('#left-fixed-sidebar').css('position','relative');
        }
        
     
      });
 
});
</script>
<?php get_footer(); ?>